<HTML><HEAD><TITLE>read_exdr(+Stream, -Term)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>read_exdr(+Stream, -Term)</H1>
A term in EXDR-format is read from the input stream Stream and
converted to the corresponding ECLiPSe term Term.


<DL>
<DT><EM>Stream</EM></DT>
<DD>Integer (stream number) or Atom (symbolic stream name).
</DD>
<DT><EM>Term</EM></DT>
<DD>A variable.
</DD>
</DL>
<H2>Description</H2>
    The predicates write_exdr/2 and read_exdr/2 can be used for letting
    ECLiPSe programs exchange data with the host language in an embedded
    environment (e.g.  Java, Tcl).  More generally, they allow exchanging
    data with agents written in programming languages that define a
    mapping from EXDR format to the language's data structures.
<P>
    EXDR defines the abstract data types Integer, Long, Double, String,
    List, Nil, Struct and Anonymous Variable. Their mapping to ECLiPSe
    data types is as follows:
<PRE>
        EXDR type       ECLiPSe type        e.g.
        ----------------------------------------------
        Integer         integer             123
        Long            integer             10000000000
        Double          float               12.3
        String          string              "abc"
        List            ./2                 [a,b,c]
        Nil             []/0                []
        Struct          compound or atom    foo(bar,3)
        Anon.Variable   var                 _
</PRE>
    Not all ECLiPSe terms have an EXDR representation, e.g. integers longer
    than 64 bits, rationals, suspensions or attributed variables.
<P>
    More information about EXDR format, including the specification of the
    serialised encoding, can be found in the Embedding and Interfacing Manual.

<H3>Modes and Determinism</H3><UL>
<LI>read_exdr(+, -) is semidet
</UL>
<H3>Fail Conditions</H3>
Fails when reaching end of file
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Stream is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Stream is not an atom or an integer.
<DT><EM>(7) string contains unexpected characters </EM>
<DD>EXDR term corrupted.
<DT><EM>(190) end of file reached </EM>
<DD>End of file (default handler fails)
<DT><EM>(192) illegal stream mode </EM>
<DD>Stream is not an input stream.
<DT><EM>(193) illegal stream specification </EM>
<DD>Stream is an illegal stream specification.
<DT><EM>(264) not an eclipse object file  </EM>
<DD>Not EXDR format.
<DT><EM>(265) bad eclipse object file version  </EM>
<DD>Unknown EXDR format version.
</DL>
<H2>Examples</H2>
<PRE>
Success:
    [eclipse 4]: open(queue(""),update,q),
                 write_exdr(q, foo(12.3,123,["hello",_])),
                 read_exdr(q, Term),
                 close(q).

    Term = foo(12.3, 123, ["hello", _131])
    yes.

Error:
    read_exdr(S, a(b,c)).    (Error 4).
    read_exdr(input, X).     (Error 192).
    read_exdr(atom, X).      (Error 193).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/ioterm/write_exdr-2.html">write_exdr / 2</A>, <A HREF="../../kernel/ioterm/read-1.html">read / 1</A>, <A HREF="../../kernel/ioterm/read-2.html">read / 2</A>
</BODY></HTML>
